package TuiLayer;;
import ModelLayer.*;
import ControlLayer.*;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Vestbjerg project
 * @GroupB2 (UCN - Computer Science DMAJ0914) 
 */
public class StatisticsUI
{
    // instance variables
    private CustomerCtr customerCtr;
    private EmployeeCtr employeeCtr;
    private ProductCtr productCtr;

    /**
     * Constructor for objects of class Statistics
     */
    public StatisticsUI()
    {
        customerCtr = new CustomerCtr();
        employeeCtr = new EmployeeCtr();
        productCtr = new ProductCtr();
    }
    
    private int getChoice()
    {
        Scanner keyboard = new Scanner(System.in);
        int choice = keyboard.nextInt();

        return choice;
    }

    // Statistics menu
    public void menuStart() 
    {
        boolean exit = false;
        String print = null;
        while(!exit) 
        {
            writeMachinerysMenu(print);
            int choice = getChoice();

            if(choice == 1) 
            {
                print = customerSortPrint();
            }
            else if(choice == 2)
            {
                print = employeeSortPrint();
            }
            else if(choice == 3) 
            {
                print = productSortPrint();
            }
            else if(choice == 0) 
            {
                exit = true;
            }

        }
    }
    
    // Write Statistics menu
    public void writeMachinerysMenu(String print) 
    {
        System.out.println("\f *** Statistics ***");
        System.out.println(" (1)Customers");
        System.out.println(" (2)Employees");
        System.out.println(" (3)Products");
        System.out.println(" (0)Back");
        if(print != null) 
        {
            System.out.println("\n " + print);

        }
        System.out.print("\n Make your choice: ");
    }

    public String customerSortPrint()
    {
        Customer foundCustomer = null;
        String print = "#:         Kr       ID         Name\n";
        print += "_________________________________________________________________\n";
        int i = 0;
        
        while(i < customerCtr.customerSort().size())
        {
            foundCustomer = customerCtr.findCustomer(customerCtr.customerSort().get(i)); 
            print += " " + (i+1) + ":        " + foundCustomer.getTotalAmount() + "       " + foundCustomer.getId() + "       " + foundCustomer.getName() + "\n";            
            i = i +1;
        }
        
        return print;
    }
    
    public String employeeSortPrint()
    {
        Employee foundEmployee = null;
        String print = "#:         Kr       ID         Name\n";
        print += "_________________________________________________________________\n";
        int i = 0;
        
        while(i < employeeCtr.employeeSort().size())
        {
            foundEmployee = employeeCtr.findEmployee(employeeCtr.employeeSort().get(i)); 
            print += " " + (i+1) + ":        " + foundEmployee.getTotalAmount() + "       " + foundEmployee.getId() + "       " + foundEmployee.getName() + "\n";    
            
            i = i +1;
        }
        return print;
    }
    
    public String productSortPrint() 
    {
        Product foundProduct = null;
        String print = "#:         Amount       ID             Name\n";
        print += "_________________________________________________________________\n";
        int i = 0;
        
        while(i < productCtr.productSort().size())
        {
            foundProduct = productCtr.findProduct(productCtr.productSort().get(i)); 
            print += " " + (i+1) + ":        " + foundProduct.getAmountSold() + "             " + foundProduct.getBarcode() + "       " + foundProduct.getName() + "\n";             
            i = i +1;
            
        }
        return print;
    }
}